package com.itheima.sh.controller;


import com.itheima.sh.clients.UserFeign;
import com.itheima.sh.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("feign")
public class FeignController {


    @Autowired
    UserFeign userFeign;

    @GetMapping("{id}")///user/
    //@HystrixCommand(fallbackMethod = "queryByIdFallBack")//降级处理的备选方法
    public User queryById(@PathVariable("id") String id){
        User user = userFeign.queryById(id);
       /* if (id.equals("itheima")){
            throw new RuntimeException("itheima");
       }*/

        return user;

    }


    /**降级方法
     *  如果调用的真实方法宕机 会启用这个方法
     * @param id
     * @return
     */
/*    public User queryByIdFallBack( String id){

        User user = new User();
        user.setNickName("已经暂停服务,请稍后再试");
        user.setName("-1");
        user.setUsername(id);

        return user;
    }*/




}
